//
//  DetailViewController.m
//  AISUPnPFinder
//
//  Created by Ares on 1/26/15.
//  Copyright (c) 2015 Ares. All rights reserved.
//

#import "DetailViewController.h"
#import <AISUPnP/AISUPnP.h>
#import "LocationViewController.h"

@interface DetailViewController ()

@end

@implementation DetailViewController

#pragma mark - Managing the detail item

- (void)setDetailItem:(id)newDetailItem {
    if (_detailItem != newDetailItem) {
        _detailItem = newDetailItem;
            
        // Update the view.
        [self configureView];
    }
}

- (void)configureView
{
    // Update the user interface for the detail item.
    if (self.detailItem)
    {
        AISUPnPDevice *device = (AISUPnPDevice *)(self.detailItem);
        NSString *description = [NSString stringWithFormat:@"USN: %@\nHost: %@\nPort: %ld\nLocation: %@", device.uniqueServiceName, device.host, device.port, device.location];
        self.detailDescriptionLabel.text = description;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self configureView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Segues

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showLocationBrowser"])
    {
        // LocationViewController *controller = (LocationViewController *)[[segue destinationViewController] topViewController];
        LocationViewController *controller = (LocationViewController *)[segue destinationViewController];
        [controller setDetailItem:self.detailItem];
        controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
        controller.navigationItem.leftItemsSupplementBackButton = YES;
    }
}

@end
